﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Xml;
using System.Reflection;
using System.Diagnostics;
using System.Drawing;
using System.Linq;

namespace iPhoneUI.Shell
{
    public class PageConfig : Config
    {
        public PageConfig(XmlNode config)
            :base(config)
        {
        }

        public byte BackgroundAlpha
        {
            get
            {
                return GetValue("@BackgroundAlpha", (byte)255);
            }
        }

        public Type PageType
        {
            get
            {
                string type = GetValue("@Type");
                if (string.IsNullOrEmpty(type) == false)
                    return Type.GetType(type);

                return typeof(Page);
            }
        }

        public Page CreateInstance()
        {
            return Activator.CreateInstance(PageType) as Page;
        }

        public IEnumerable<WidgetRefConfig> WidgetRefs
        {
            get
            {
                return GetList<WidgetRefConfig>(n => new WidgetRefConfig(n), "widgetRef");
            }
        }

        public IEnumerable<WidgetConfig> Widgets
        {
            get
            {
                return GetList<WidgetConfig>(n => new WidgetConfig(n), "widget");
            }
        }

        public Bitmap CreateBackgroundImage()
        {
            return ShellConfig.CreateImage(GetValue("@Image"));
        }
    }
}
